<script setup lang="ts">
import { reactive } from 'vue';
import router from '@/router';
import { CreatePost } from '@/request/postRequest';
import { ElMessage } from 'element-plus';
const form = reactive({
  postName: "",
  postContent: ""
})

const onSubmit = (postName: any, postContent: any) => {
  CreatePost(postName, postContent).then(res => {
    let message = res.data.detail || '创建成功';
    ElMessage.success(message);
    router.push('/');
  })
}


const backHome = function () {
  router.push('/');
}
</script>

<template>
  <main>
    <el-form :model="form" label-width="120px" class="my_form">
      <el-form-item label="帖子标题">
        <el-input v-model="form.postName" />
      </el-form-item>
      <el-form-item label="帖子内容">
        <el-input v-model="form.postContent" type="textarea" :autosize="{ minRows: 5, maxRows: 10 }" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit(form.postName, form.postContent)">发帖</el-button>
        <el-button @click="backHome">取消</el-button>
      </el-form-item>
    </el-form>
  </main>
</template>

<style scoped></style>